package com.gitee.controller;

import com.gitee.bo.UserBo;
import com.gitee.enums.ResponseEnum;
import com.gitee.pojo.User;
import com.gitee.service.IUserService;
import com.gitee.vo.PageVo;
import com.gitee.vo.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping
    public ResponseVo<PageVo<User>> pageUser(String keywords, Boolean enabled, Boolean admin, Integer pageNum, Integer pageSize) {
        PageVo<User> userPageVo = userService.pageUser(keywords, enabled, admin, pageNum, pageSize);
        return ResponseVo.ok(userPageVo);
    }

    @PutMapping("/{userId}")
    public ResponseVo<String> updateUser(@PathVariable Integer userId, @RequestBody UserBo userBo) {
        userService.updateUser(userId, userBo);
        return ResponseVo.ok(ResponseEnum.UPDATE_SUCCESS);
    }

    @DeleteMapping("/{userId}")
    public ResponseVo<String> deleteUser(@PathVariable Integer userId) {
        userService.deleteUser(userId);
        return ResponseVo.ok(ResponseEnum.DELETE_SUCCESS);
    }

    @DeleteMapping("/batch")
    public ResponseVo<String> deleteUsers(@RequestBody Integer[] userIds) {
        userService.deleteUsers(userIds);
        return ResponseVo.ok(ResponseEnum.DELETE_SUCCESS);
    }

}
